package indzcraft.loader;

import java.util.HashMap;


public class Equipment {
	
	public HashMap<String,Integer> slotTable = new HashMap<String,Integer>();
	
	public HashMap<String,ItemEquiped> equipment = new HashMap<String,ItemEquiped>();
	
	public Equipment(){
		slotTable.put("head", 0);
		slotTable.put("neck", 1);
		slotTable.put("shoulder", 2);
		slotTable.put("back", 3);
		slotTable.put("chest", 4);
		slotTable.put("shirt", 5);
		slotTable.put("tabard", 6);
		slotTable.put("wrist", 7);
		slotTable.put("hands", 8);
		slotTable.put("waist", 9);
		slotTable.put("legs", 10);
		slotTable.put("feet", 11);
		slotTable.put("finger1", 12);
		slotTable.put("finger2", 13);
		slotTable.put("trinket1", 14);
		slotTable.put("trinket2", 15);
		slotTable.put("mainHand", 16);
		slotTable.put("offHand", 17);
		slotTable.put("ranged", 18);
	}
	
	public Integer getSlotTableId(String slotName){
		if(slotTable.containsKey(slotName)){
			return slotTable.get(slotName);
		}
		return null;
	}
	
	/*public String getSlotTableName(int id){
		if(slotTable.containsValue(id)){
			for(String name : slotTable.keySet()){
				if(slotTable.get(name) == id){
					return name;
				}
			}
		}
		return null;
	}*/
	
	public ItemEquiped get(String slotName){
		return equipment.get(slotName);
	}
	
	public void put(String slot,ItemEquiped ie){
		equipment.put(slot, ie);
	}
	
	public void print(){
		for(String slot: equipment.keySet()){
			System.out.println(slot);
			equipment.get(slot).print();
			System.out.println("====");
		}
	}
	
	public Item getStats(){
		Item i = new Item(); // missbraucht als datenspeicher
		for(String slot: equipment.keySet()){
			ItemEquiped ie = equipment.get(slot);
			i.setHaste(i.getHaste()+ie.getReforgedHaste());
			i.setCrit(i.getCrit()+ie.getReforgedCrit());
			i.setHit(i.getHit()+ie.getReforgedHit());
			i.setMastery(i.getMastery()+ie.getReforgedMastery());
			i.setExp(i.getExp()+ie.getReforgedExp());
			// gems
			boolean colorMatch = true;
			for(int g = 0;g < ie.gem.length;g++){
				if(ie.gemSlot[g].equals("") || ie.gem[g] == null){
					colorMatch = false;
				}else{
					i.setHaste(i.getHaste()+ ie.gem[g].getHaste());
					i.setHit(i.getHit()+ ie.gem[g].getHit());
					i.setMastery(i.getMastery()+ ie.gem[g].getMastery());
				}
			}
			if(ie.socketBonus != null && colorMatch){
				i.setHaste(i.getHaste()+ie.socketBonus.getHaste());
				i.setMastery(i.getMastery()+ie.socketBonus.getMastery());
				i.setExp(i.getExp()+ie.socketBonus.getExp());
				i.setCrit(i.getCrit()+ie.socketBonus.getCrit());
				i.setHit(i.getHit()+ie.socketBonus.getHit());
			}
			// enchant
			if(ie.getEnchant() != null){
				Enchant e = ie.getEnchant();
				i.setHaste(i.getHaste()+e.getHaste());
				i.setMastery(i.getMastery()+e.getMastery());
				i.setExp(i.getExp()+e.getExp());
				i.setCrit(i.getCrit()+e.getCrit());
				i.setHit(i.getHit()+e.getHit());
			}
		}
		return i;
	}

	public Item getReforgings() {
		Item i = new ItemEquiped(); // missbraucht als datenspeicher
		for(String slot: equipment.keySet()){
			Reforge r = equipment.get(slot).getReforge();
			if(r != null){
				i.setHaste(i.getHaste() + equipment.get(slot).getReforgedHaste()-equipment.get(slot).getHaste());
				i.setCrit(i.getCrit() + equipment.get(slot).getReforgedCrit()-equipment.get(slot).getCrit());
				i.setHit(i.getHit() + equipment.get(slot).getReforgedHit()-equipment.get(slot).getHit());
				i.setMastery(i.getMastery() + equipment.get(slot).getReforgedMastery()-equipment.get(slot).getMastery());
				i.setExp(i.getExp() + equipment.get(slot).getReforgedExp()-equipment.get(slot).getExp());
			}
		}
		return i;
	}
}
